#include "SharedTemplates/Visitors.hpp"
#include <iostream>

struct stA;
struct stB;

struct Base
{
	// 通用访问者类型
	typedef Visitor<stA, stB> MyVistor;	// 访问后进行的操作(抽象接口)
	virtual void Accept(MyVistor&) = 0;	// 访问使用
};

struct stA : Base
{
	double val;
	void Accept(Base::MyVistor& v)
	{
		v.Visit(*this);
	}
};

struct stB : Base
{
	int val;
	void Accept(Base::MyVistor& v)
	{
		v.Visit(*this);
	}
};

struct PrintVisitor : Base::MyVistor
{
	void Visit(const stA& a)
	{
		std::cout << "from stA: " << a.val << std::endl;
	}

	void Visit(const stB& b)
	{
		std::cout << "from stB: " << b.val << std::endl;
	}
};

int main()
{
	PrintVisitor vis;
	stA a;
	a.val = 8.91;
	stB b;
	b.val = 8;
	Base* base = &a;
	base->Accept(vis);
	base = &b;
	base->Accept(vis);

}